package intranet.models;
import java.sql.*;
public class NewsEventsModel {
	Connection DBConnection=null;
	public NewsEventsModel(){
		DatabaseModel DBModel=new DatabaseModel();
		DBConnection=DBModel.GetConnection();
	}
	/* SEELECT NEWS_EVENTS INFO */
	public ResultSet SelectNewsEvents(int news_id){
		ResultSet result=null;
		String Conditional_String=(news_id!=0)?"WHERE NEWS_ID="+news_id:"";
		try{
			Statement ConStatement=DBConnection.createStatement();
			String Sql="SELECT NEWS_ID,NEWS_TITLE,DBMS_LOB.SUBSTR(NEWS_DESC,DBMS_LOB.GETLENGTH(NEWS_DESC),1) AS NEWS_DESC,FRONT_IMAGE_FILE FROM NEWS_EVENTS "+Conditional_String+" ORDER BY DATE_POST DESC";
			result=ConStatement.executeQuery(Sql);
		}catch(Exception e){
			e.getLocalizedMessage();
		}
		return result;
	}	
	/* SELECT NEWS_EVENTS IMAGES */
	public ResultSet SelectNewsEventsImages(int news_id){
		ResultSet result=null;
		try{
			Statement ConStatement=DBConnection.createStatement();
			String Sql="SELECT NEWS_ID,IMAGE_FILE FROM NEWS_EVENTS_IMAGES WHERE NEWS_ID="+news_id;
			result=ConStatement.executeQuery(Sql);
		}catch(Exception e){
			e.getLocalizedMessage();
		}
		return result;
	}
}
